/*
* Unless required by applicable law or agreed to in writing, software 
* distributed under the License is distributed on an "AS IS" BASIS, 
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
* See the License for the specific language governing permissions and 
* limitations under the License. 
*/
#ifndef CMDOPTION_H_
#define CMDOPTION_H_
#include "Abstract.h"


class cmdFlag : public AbstractOption
{
protected: 
	
	cmdFlag(char k, const char* desc, AbstractArg* pArg) : AbstractOption(k, desc, pArg)
	{
		present = false;
	}
	
	cmdFlag(char k, const char* verKey, const char* desc, AbstractArg* arg ) : 
		AbstractOption(k, verKey, desc, arg) 
	{
		present = false;
	}
	
public:
	cmdFlag(char k, const char* desc) : AbstractOption(k, desc, NULL) {present = false;}
	cmdFlag(char k, const char* verKey, const char* desc) : 
				AbstractOption(k, verKey, desc, NULL) {present = false;}
	virtual ~cmdFlag() {}
	bool operator ==(bool val) {return present == val;}
	bool operator !=(bool val) {return present != val;}
	void operator =(bool val) {present = val; initialized = true;}
	
	virtual bool ExpectValue() {return false;}

	bool Value() { return present; }

	bool Parse(char* str)
	{
		std::string s = str;
		trim(s);
		return ParseTo(s);
	}

	
	bool Parse(std::string& str)
	{
		std::string s = str;
		trim(s);
		return ParseTo(s);
	}

	
	bool ParseTo(std::string& s)
	{
		size_t pos = 0;
		// check verbose key 
		if (s.find("--") != std::string::npos) {
			
			pos = s.find(verboseKey);
			if (pos != std::string::npos)
					present = true;
			s.erase(0, pos); // remove key
		}
		else if(s[0] == '-') {
		
			pos = s.find(key);
			if (pos != std::string::npos)
					present = true;
			s.erase(0, pos); // remove key
		}
		if (present)
			trim(s);
		initialized = true;
		return present;
	}
	
	
protected:
	bool present;
};


template <class T = const char*>
class cmdOption : public cmdFlag
{
public:
	cmdOption(char k, const char* desc, AbstractArg* pArg) : cmdFlag(k, desc, pArg) 
	{
		allOptions += k;
	}
	cmdOption(char k, const char* verKey, const char* desc, AbstractArg* arg ) : 
		cmdFlag(k, verKey, desc, arg) 
	{
		allOptions += k;
	}
					
	virtual ~cmdOption() {}

	bool ExpectValue() {return true;}
	
	
};




#endif /*CMDOPTION_H_*/
